package com.zunipe.screen;

import com.zunipe.ZunipeTools;
import com.zunipe.config.ZunipeConfig;
import com.zunipe.until.Util;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ScreenTexts;
import net.minecraft.client.gui.screen.option.OptionsScreen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.CyclingButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;

public class ScanningBoxOptionScreen extends Screen
{
    private final Screen parent;

    public ScanningBoxOptionScreen(Screen parent)
    {
        super(new LiteralText("垃圾桶扫描者设置"));
        this.parent = parent;
    }

    @Override
    public void init()
    {
        this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height / 6 + 168, 200, 20, ScreenTexts.DONE, button -> this.client.setScreen(this.parent)));
        this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height / 6 + 118, 200, 20, new LiteralText("加载配置"), button ->
        {
            ZunipeConfig.loadConfig();
            this.client.setScreen(this.parent);
        }));
        this.addDrawableChild(new ButtonWidget(this.width / 2 + 10, this.height / 6 + 143, 90, 20, new LiteralText("物品列表"), button ->
                net.minecraft.util.Util.getOperatingSystem().open(ZunipeConfig.PATH.resolve(ZunipeTools.MODID + "_itemlist.txt").toFile())));

        this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height / 6 + 143, 90, 20, new LiteralText("排除列表"), button ->
                net.minecraft.util.Util.getOperatingSystem().open(ZunipeConfig.PATH.resolve(ZunipeTools.MODID + "_exclusionitemlist.txt").toFile())));
        this.addDrawableChild(CyclingButtonWidget.builder(ScanningMode::getTranslatableName).values(ScanningMode.values()).initially(Util.scanningMode).build(this.width / 2 - 100, this.height / 6 + 93, 200, 20, new LiteralText("扫描模式"), (a, b) -> Util.scanningMode = b));
    }

    @Override
    public void render(MatrixStack matrices, int mouseX, int mouseY, float delta)
    {
        this.renderBackground(matrices);
        OptionsScreen.drawCenteredText(matrices, this.textRenderer, this.title, this.width / 2, 15, 0xFFFFFF);
        super.render(matrices, mouseX, mouseY, delta);
    }

    public enum ScanningMode
    {
        FORWARD("向前"), BACKWARD("向后");
        private final String name;

        ScanningMode(String name)
        {
            this.name = name;
        }

        public Text getTranslatableName()
        {
            return new LiteralText(this.name);
        }
    }
}
